#!/usr/local/bin/python
#==============================================================================
#
#  $Id: rshclient,v 1.3 2001/02/05 17:46:38 mike Exp $
#
"""
   RSH client test program.
"""
#
#  Copyright (C) 2000 Michael A. Muller
#
#  Permission is granted to use, modify and redistribute this code,
#  providing that the following conditions are met:
#
#  1) This copyright/licensing notice must remain intact.
#  2) If the code is modified and redistributed, the modifications must 
#  include documentation indicating that the code has been modified.
#  3) The author(s) of this code must be indemnified and held harmless
#  against any damage resulting from the use of this code.
#
#  This code comes with ABSOLUTELY NO WARRANTEE, not even the implied 
#  warrantee of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#
#  $Log: rshclient,v $
#  Revision 1.3  2001/02/05 17:46:38  mike
#  Fixed copyright dates.
#
#  Revision 1.2  2000/07/29 21:15:48  mike
#  Added docs.
#
#
#==============================================================================

import os, sys

# remove the current directory from the search path so that this runs ok
# from the dopy library directory
if sys.path[0] in ('', os.curdir):
   del sys.path[0]

import dopy.rsh

# get the remote object

print 'connecting to local shell...'
obj = dopy.rsh.remote('rshserver 2>err.out', 'test')

# try a simple method invocation

try:
   if obj.hello('client!') == 'hello client!':
      print 'test of basic method invocation ok'
   else:
      raise Exception()
except Exception, ex:
   import traceback, sys
   traceback.print_exc(sys.exc_info())
   print 'test of basic method invocation failed'

# try sending keyword parms

try:
   if obj.kwparms(p1 = 100, p2 = 200) == (100, 200):
      print 'test of keyword parms ok'
   else:
      raise Exception()
except Exception, ex:
   print 'test of keyword parms failed'

# try calling a function that raises an exception

try:
   obj.raiseException()
except Exception, ex:
   print 'test of exceptions ok'
else:
   print 'test of exceptions failed'
